﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ProvisorioHelpDesk
{
    public partial class Frm_MenuPrincipal : Form
    {
        public Frm_MenuPrincipal()
        {
            InitializeComponent();
        }

        private void patrimoniosCPUBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.patrimoniosCPUBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.testerDataSet);
        }

        int bandera;

        private void Frm_MenuPrincipal_Load(object sender, EventArgs e)
        {
            // TODO: esta línea de código carga datos en la tabla 'testerDataSet1.Sectores' Puede moverla o quitarla según sea necesario.
            this.sectoresTableAdapter.Fill(this.testerDataSet1.Sectores);
            // TODO: esta línea de código carga datos en la tabla 'testerDataSet1.DatosPersonales' Puede moverla o quitarla según sea necesario.
            this.datosPersonalesTableAdapter.Fill(this.testerDataSet1.DatosPersonales);
            // TODO: esta línea de código carga datos en la tabla 'testerDataSet.PatrimoniosCPU' Puede moverla o quitarla según sea necesario.
            this.patrimoniosCPUTableAdapter.Fill(this.testerDataSet.PatrimoniosCPU);
            toolStripTextBox1.Text = bindingNavigatorPositionItem.Text + " " + bindingNavigatorCountItem;
        }

        private void groupBox3_Enter(object sender, EventArgs e)
        {

        }

        private void salirDelProgramaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("¿Está seguro que desea abandonar la aplicación?","Abandonando el sistema",MessageBoxButtons.YesNo))
            {
                Application.Exit();
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                patrimoniosCPUBindingNavigatorSaveItem.PerformClick();
                button1.Enabled = true;
                button2.Enabled = true;
                button3.Enabled = false;
                button4.Enabled = false;
                button5.Enabled = true;
                groupBox1.Enabled = false;
                groupBox2.Enabled = false;
                groupBox3.Enabled = false;
                groupBox4.Enabled = false;
                groupBox5.Enabled = false;
                menuStrip1.Enabled = true;
            }
            catch
            {
                MessageBox.Show("Lo siento pero se originó un error, verifique que los datos sean correctos");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            bandera = 2;
            if (DialogResult.Yes == MessageBox.Show("¿Está seguro que desea eliminar el registro?", "Advertencia", MessageBoxButtons.YesNo))
            {
                bindingNavigatorDeleteItem.PerformClick();
                bindingNavigatorMoveLastItem.PerformClick();
                button3.Enabled = false;
                button4.Enabled = false;
                toolStripTextBox1.Text = bindingNavigatorPositionItem.Text + " " + bindingNavigatorCountItem;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bandera = 1;
            groupBox1.Enabled = true;
            groupBox2.Enabled = true;
            groupBox3.Enabled = true;
            groupBox4.Enabled = true;
            groupBox5.Enabled = true;
            bindingNavigatorAddNewItem.PerformClick();
            button2.Enabled = false;
            button3.Enabled = true;
            button4.Enabled = true;
            button5.Enabled = false;
            button1.Enabled = false;
            iD_PatrimonioCPUTextBox.Focus();
            cPU_EstadoDelPatrimonioCheckBox.Checked = true;
            menuStrip1.Enabled = false;
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("¿Desea editar este registo?", "Advertencia", MessageBoxButtons.YesNo))
            {
                bandera = 3;
                groupBox1.Enabled = true;
                groupBox2.Enabled = true;
                groupBox3.Enabled = true;
                groupBox4.Enabled = true;
                groupBox5.Enabled = true;
                button1.Enabled = false;
                button2.Enabled = false;
                button3.Enabled = true;
                button4.Enabled = true;
                button5.Enabled = false;
                iD_PatrimonioCPUTextBox.Enabled = false;
                menuStrip1.Enabled = false;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (bandera == 1)
            {
                bindingNavigatorDeleteItem.PerformClick();
                groupBox1.Enabled = false;
                groupBox2.Enabled = false;
                groupBox3.Enabled = false;
                groupBox4.Enabled = false;
                groupBox5.Enabled = false;
                button1.Enabled = true;
                button2.Enabled = true;
                button3.Enabled = false;
                button4.Enabled = false;
                button5.Enabled = true;
            }
            else
            if (bandera == 2)
            {
                groupBox1.Enabled = false;
                groupBox2.Enabled = false;
                groupBox3.Enabled = false;
                groupBox4.Enabled = false;
                groupBox5.Enabled = false;
                button1.Enabled = true;
                button2.Enabled = true;
                button3.Enabled = false;
                button4.Enabled = false;
                button5.Enabled = true;
            }
            else
            if (bandera == 3)
            {
                groupBox1.Enabled = false;
                groupBox2.Enabled = false;
                groupBox3.Enabled = false;
                groupBox4.Enabled = false;
                groupBox5.Enabled = false;
                button1.Enabled = true;
                button2.Enabled = true;
                button3.Enabled = false;
                button4.Enabled = false;
                button5.Enabled = true;
            }
            menuStrip1.Enabled = true;
            toolStripTextBox1.Text = bindingNavigatorPositionItem.Text + " " + bindingNavigatorCountItem;
        }

        private void bindingNavigatorPositionItem_TextChanged(object sender, EventArgs e)
        {
            toolStripTextBox1.Text = bindingNavigatorPositionItem.Text + " " + bindingNavigatorCountItem;
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            bindingNavigatorMovePreviousItem.PerformClick();
        }

        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            bindingNavigatorMoveFirstItem.PerformClick();
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            bindingNavigatorMoveNextItem.PerformClick();
        }

        private void toolStripMenuItem4_Click(object sender, EventArgs e)
        {
            bindingNavigatorMoveLastItem.PerformClick();
        }

       
    }
}
